package com.dream.utils.date;

import java.util.HashMap;
import java.util.Map;

import com.dream.utils.exception.BusinessException;

/**
 * populate a date from  String to Date
 * @copyright evan
 * @author evan
 * @Revision
 * @date 2012/8/19
 */
public enum WeekType {
	SUNDAY(1),
	MONDAY(2),
	TUESDAY(3),
	WEDNESDAY(4),
	THURSDAY(5), 
	FRIDAY(6) ,
	SATURDAY(7) ;
	private final int value;
	private static final Map<Integer,WeekType> map;
	static{
		map = new HashMap<Integer,WeekType>(14);
		map.put(SUNDAY.toInteger(), SUNDAY);
		map.put(MONDAY.toInteger(), MONDAY);
		map.put(TUESDAY.toInteger(), TUESDAY);
		map.put(WEDNESDAY.toInteger(), WEDNESDAY);
		map.put(THURSDAY.toInteger(), THURSDAY);
		map.put(FRIDAY.toInteger(), FRIDAY);
		map.put(SATURDAY.toInteger(), SATURDAY);
	}
	private WeekType(int val){
		value = val;
	}
	/**
	 * get the integer value
	 * @return
	 */
	public int toInteger(){
		return value;
	}
	
	/*
	 * instance week by  value
	 */
	public static WeekType instance(int val){
		
		if(map.containsKey(val)){
			return map.get(val);
		}else{
			throw new BusinessException("Unsupport to instance the val= " + val);
		}
		
	}
}
